﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Kugar.MVC.MobileUI.WeUI.Helpers
{
    public static class ControlExt
    {
        public static T Css<T>(this T src, string className) where T : WeUIElementBase
        {
            if (string.IsNullOrWhiteSpace(className))
            {
                return (T)src;
            }

            src._attrs.Class(className);

            return src;
        }

        public static T Style<T>(this T src, string styleName, string value) where T : WeUIElementBase
        {
            src._attrs.MergeAttr("Style", $"{styleName}:{value}");

            return src;
        }

        public static T Style<T>(this T src, string styleValue) where T : WeUIElementBase
        {
            if (string.IsNullOrWhiteSpace(styleValue))
            {
                return src;
            }

            src._attrs.MergeAttr("Style", $"{styleValue}");

            return src;
        }

        public static T ID<T>(this T src, string id) where T : WeUIElementBase
        {
            src._attrs.ID(id);

            return src;
        }

        public static T Attr<T>(this T src, string attrName, string value) where T : WeUIElementBase
        {
            src._attrs.MergeAttr(attrName, value);

            return src;
        }

        public static T Data<T>(this T src, string dataName, string value) where T : WeUIElementBase
        {
            if (!dataName.StartsWith("data-",StringComparison.CurrentCultureIgnoreCase))
            {
                dataName = "data-" + dataName;
            }

            src._attrs.MergeAttr(dataName, value);

            return src;
        }

    }
}